{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2544460d",
   "metadata": {},
   "source": [
    "# Basics: Prompt, Client, and Responses"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1c60fd08",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'triton_trt_llm'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtriton_trt_llm\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m HttpTritonClient\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'triton_trt_llm'"
     ]
    }
   ],
   "source": [
    "from triton_trt_llm import HttpTritonClient"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c99ac30",
   "metadata": {},
   "source": [
    "#### Step 1: Structure the Query in a Prompt Template"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66c35817",
   "metadata": {},
   "outputs": [],
   "source": [
    "NEMOTRON_PROMPT_TEMPLATE = (\n",
    " \"\"\"<extra_id_0>System\n",
    "{system}\n",
    "<extra_id_1>User\n",
    "{prompt}\n",
    "<extra_id_1>Assistant\n",
    "\"\"\"\n",
    ")\n",
    "system = \"You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Please ensure that your responses are positive in nature.\"\n",
    "prompt = 'What is the fastest land animal?'\n",
    "prompt = NEMOTRON_PROMPT_TEMPLATE.format(prompt=prompt, system=system)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdd7ab41",
   "metadata": {},
   "source": [
    "#### Step 2: Create the Triton Client"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc94f643",
   "metadata": {},
   "outputs": [],
   "source": [
    "triton_url = \"llm:8000\"\n",
    "client = HttpTritonClient(triton_url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47c24666",
   "metadata": {},
   "outputs": [],
   "source": [
    "pload = {\n",
    "            'prompt':[[prompt]],\n",
    "            'tokens':64,\n",
    "            'temperature':1.0,\n",
    "            'top_k':1,\n",
    "            'top_p':0,\n",
    "            'beam_width':1,\n",
    "            'repetition_penalty':1.0,\n",
    "            'length_penalty':1.0\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "443f4fbd",
   "metadata": {},
   "source": [
    "#### Step 3: Load the Model and Generate Response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "122d2f10",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "model_name = \"ensemble\"\n",
    "client.load_model(model_name)\n",
    "val = client.request(model_name, **pload)\n",
    "print(val)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
